using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Curchy.PERTToolbox.Entity;
using Curchy.PERTToolbox.Service;

namespace Curchy.PERTToolbox.WinUI
{
    public partial class ProjectDefinition : Form
    {
        public ProjectDefinition()
        {
            InitializeComponent();

            grdDetails.SelectedObject = new Project();
        }

        public ProjectDefinition(Project project)
        {
            InitializeComponent();

            grdDetails.SelectedObject = project;
        }

        private void generateEstimationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Project prj = (Project)grdDetails.SelectedObject;
            if (prj.Calendar == null)
                prj.Calendar = CalendarFactory.Instance.GetSystemSettings().GlobalCalendars[0];
            Estimation est = EstimationFactory.Instance.GeneratePERT(prj);
            EstimationResult rst = new EstimationResult(est);
            rst.MdiParent = MdiParent;
            rst.Show();
        }

        private void ProjectDefinition_Load(object sender, EventArgs e)
        {
            menuStrip.Visible = false;
        }

        private void saveProjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Project project = (Project)grdDetails.SelectedObject;
            DialogResult result = openFileDialog.ShowDialog();
            if(result == DialogResult.OK)
            {
                PersistanceToolbox<Project>.Save(project, openFileDialog.FileName);
            }
        }
    }
}